<script>
    $(function(){
		//展开功能
		var BN_height;
		if(GetQueryString('book_id')){
			$('.spread span').show()
			$('.bookName').animate({ height: $('.bookName').height()+2+"px" })
			$('.spread span').text('收回')
		}
		if ($('.bookName').height() > 60) {
			BN_height = $('.bookName').height()
			$('.bookName').height('62') 
			$('.spread span').show()
		}else{
			$('.spread span').hide()
		}
		$('.spread span').click(function () {
			let status = $('.spread span').text().trim()
			if (status == '展开') {
				$('.bookName').animate({ height: BN_height+2+"px" })
				$('.spread span').text('收回')
			} else {
				$('.bookName').animate({ height: "62px" })
				$('.spread span').text('展开')
			}
		})
	})

	let stackTableActive = Number(localStorage.getItem('stackTableActive'))
	$('.type li').eq(stackTableActive+1).children().addClass('active').parent().siblings().children().removeClass('active')
	$('.box').children().eq(stackTableActive).show().siblings().hide()
	$('.addBtn').attr('id','create_'+$('.type li').eq(stackTableActive+1).children().attr('id'))
	$('.tableDelete').attr('target-form',$('.type li').eq(stackTableActive+1).children().attr('id')+' .ids_Table')
	$('.tableDelete').attr('id','delete_'+$('.type li').eq(stackTableActive+1).children().attr('id'))
	$('.all').attr('checked-table',$('.type li').eq(stackTableActive+1).children().attr('id'))
	function changeTable(elem,e){
		$('.all').prop("checked", false);
		$('.'+elem).show().siblings().hide()
		$(e).addClass('active').parent().siblings().children('a').removeClass('active')
		if(elem == 'dataTable'){
			$('.tDiv').height($('.tBody').height() - 59 - 34)
			// $('.tableScroll').css({
			// 	'overflow-y':'scroll',
			// 	'height':$('.tBody').height() + 0
			// })
		}
		$('.addBtn').show()
		$('.addBtn').attr('id','create_'+elem)
		$('.tableDelete').attr('target-form',elem+' .ids_Table')
		$('.tableDelete').attr('id','delete_'+elem)
		$('.all').attr('checked-table',elem)
		localStorage.setItem('stackTableActive',$('.'+elem).index())
	}
	$('.addBtn').on('click',function(){
		switch ($(this).attr('id')) {
			case 'create_content':
				var $modal = $('#create-content-modal');
				$modal.modal({backdrop: 'static', keyboard: false});
				break;
			case 'create_verTable':
				var $modal = $('#create-versions-modal');
				$modal.on('shown.bs.modal', function () {
					$('#picker_ebook11').html('<div>上传</div>')
					$("#picker_ebook11").SentUploader({
						server:"{:url('Upload/Uploadtxt')}",
						fileNumLimit:1,
						hiddenName: 'text_content',
						hiddenValType:2,
						fileSingleSizeLimit:50*1024*1024,
					});
				});	
				$modal.modal({backdrop: 'static', keyboard: false});
				break;
			case 'create_dataTable':
				var $modal = $('#create-data-modal');
				$modal.modal({backdrop: 'static', keyboard: false});
				break;
			case 'create_textTable':
				var $modal = $('#create-text-modal');
				$modal.on('shown.bs.modal', function () {
					$('#picker_text').html('<div>上传文件</div>')
					$("#picker_text").SentUploader({
						server:"{:url('Upload/Uploadtxt')}",
						fileNumLimit:1,
						hiddenName: 'file_path1',
						hiddenFileName: 'textfile_name',
						listName: 'fileList_ebook',
						hiddenValType:2,
						fileSingleSizeLimit:50*1024*1024,
					});
					$('#create-text-modal #book_id').val($('.bookName li a.active').data('bookid'))
				});	
				$modal.modal({backdrop: 'static', keyboard: false});
				break;
		}
		
	})

	$('.tableDelete').on('click',function(){
		switch ($(this).attr('id')) {
			case 'delete_content':
				
				break;
			case 'delete_verTable':
				$(this).attr('url','/admin/book/delMaterualData?type=replace')
				break;
			case 'delete_dataTable':
				$(this).attr('url','/admin/book/delMaterualData?type=data')
				break;
			case 'delete_textTable':
				$(this).attr('url','/admin/book/delMaterualData?type=txt')
				break;
		}
	})
	//全选的实现
	$(".check-allTable").click(function() {
		let tableName = $(this).attr('checked-table')
		$(`.${tableName} .check-allTable`).prop("checked", this.checked);
		$(`.${tableName} .ids_Table`).prop("checked", this.checked);
		event.stopPropagation();
	});
	$('#checkTableALL').click(function(){
		let tableName = $(this).children().attr('checked-table')
		let checked = $(`.${tableName} .check-allTable`).prop("checked")
		$(this).children().prop('checked',!checked)
		$(`.${tableName} .check-allTable`).prop('checked',!checked)
		$(`.${tableName} .ids_Table`).prop("checked", !checked);
	})
	$(".ids_Table").click(function() {
		let tableName = $(this).attr('checked-table')
		var option = $(`.${tableName} .ids_Table`);
		option.each(function(i) {
			if (!this.checked) {
				$(`.${tableName} .check-allTable`).prop("checked", false);
				return false;
			} else {
				$(`.${tableName} .check-allTable`).prop("checked", true);
			}
		});
	});
	
	// 上传文本
	$("#text_uplpad").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	
	// 上传版本
	$("#versions_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	// 上传版本
	$("#versions_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	// 上传数据
	$("#data_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	// 上传百文
	$("#baidu_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	// 上传抖文
	$("#douyin_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	// 上传微文
	$("#weibo_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});

	
	$('.downLoad').click(function(){
		let name = $(this).data('name')
		let aDom = document.createElement('a');
		aDom.style.display = 'none';
		aDom.href = 'http://'+window.location.host+'/'+$(this).data('url');
		aDom.setAttribute('download', name);
		document.body.appendChild(aDom);aDom.click();
		document.body.removeChild(aDom);
	})

    
</script>